import { getTenantID, getUserID, requestFunCompon } from '@/utils';

import { useRequest } from 'umi';

export const useResourRangeTable = (currentKey: string) => {
  const getTableDataSource = useRequest(
    (id: string) => {
      let reqUrl = `/resourceController/treeGrid`;
      let bodyParams = {
        // positionID: getPosIDs(),
        userID: getUserID(),
        dicTypeIds: `${getTenantID()}0000`,
        pID: id,
        resourceType: currentKey == 'resRange' ? 2 : currentKey == 'resOpera' ? 3 : null,
      };
      return requestFunCompon('POST', reqUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess(data: any, params: [id: string]): void {},
    },
  );

  const reloadTableDataSource = (id: string) => getTableDataSource.run(id);

  const tableData = getTableDataSource?.data?.obj ?? [];

  const tableLoading = getTableDataSource.loading;

  return {
    reloadTableDataSource,
    tableDataSource: tableData,
    tableLoading,
  };
};
